package sk.octopuss.archery.domain;

import java.util.Date;
import java.util.HashSet;
import java.util.Set;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import javax.validation.constraints.NotNull;

import org.hibernate.validator.constraints.URL;
import org.springframework.format.annotation.DateTimeFormat;

@Entity
public class User {
	@NotNull
    private String name;

    public String getName() {
		return name;
	}

	public void setName(final String name) {
		this.name = name;
	}

	public String getSurname() {
		return surname;
	}

	public void setSurname(final String surname) {
		this.surname = surname;
	}

	public Date getBirthDate() {
		return birthDate;
	}

	public void setBirthDate(final Date birthDate) {
		this.birthDate = birthDate;
	}

	public String getUsername() {
		return username;
	}

	public void setUsername(final String username) {
		this.username = username;
	}

	public String getPassword() {
		return password;
	}

	public void setPassword(final String password) {
		this.password = password;
	}

	

	public Long getId() {
		return id;
	}

	public void setId(final Long id) {
		this.id = id;
	}
	

	public boolean isActive() {
		return active;
	}

	public void setActive(final boolean active) {
		this.active = active;
	}



	public String getOpenID() {
		return openID;
	}

	public void setOpenID(final String openID) {
		this.openID = openID;
	}


	public Set<Role> getRoles() {
		return roles;
	}



    private String surname;

    @NotNull
    @Temporal(TemporalType.TIMESTAMP)
    @DateTimeFormat(pattern="dd.MM.yyyy")
    private Date birthDate;


    private String username;


    private String password;
    
    @NotNull
    private boolean active = true;

    
    @ManyToMany
    @JoinTable(name = "APP_USER_ROLE",
       joinColumns = { @JoinColumn(name = "USER_ID") },
       inverseJoinColumns = { @JoinColumn(name = "ROLE_ID") })
    private final Set<Role> roles = new HashSet<Role>();
    
    
    
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Column(name = "id")
    private Long id;
    
    @URL
    private String openID;
}
